import 'package:compact_dio/compact_dio.dart';

class TestExceptionHandler extends ExceptionHandler {
  @override
  String handleException(DioException exception) {
    if (exception.response?.statusCode == 401) {
      return '登录失效，请重新登录';
    } else if (exception.response?.data) {
      return exception.response!.data['msg'];
    } else {
      switch (exception.type) {
        case DioExceptionType.connectionTimeout:
          return '连接超时';
        case DioExceptionType.sendTimeout:
          return '发送超时';
        case DioExceptionType.receiveTimeout:
          return '接收超时';
        case DioExceptionType.badResponse:
          return '响应错误';
        case DioExceptionType.cancel:
          return '请求取消';
        case DioExceptionType.unknown:
          return '其他错误';
        default:
          return '未知错误';
      }
    }
  }
}
